#ifndef __CHATTER_HXX__
#define __CHATTER_HXX__

#include "mydll.h"
#include "mytypes.h"
#include "mythread.hxx"
#include "taskdefs.h"

typedef void (*tUpdateFunc)(void);


//class OTConnManager;
//class ITConnManager;
//class MVHandler;
//class WFAudioRecorder;
//class RecordHandler;
class GroupMgr;
class TStatusMgr;
class STConn;


class EXPORT Chatter	:	public Thread
{
public:
////////////////////////////////////////////////////////
// typedefs
////////////////////////////////////////////////////////
	typedef enum
	{
		CHATTER_STATE_UNKNOWN,
		CHATTER_STATE_STARTINGUP,
		CHATTER_STATE_RUNNING,
		CHATTER_STATE_SHUTTINGDOWN,
		CHATTER_STATE_FINISHED
	}tChatterState;

	/**
	 * @brief	:	Constructor
	 * @param update_func	:	Callback when state of the chatter changed. 
	 */
	Chatter(tUpdateFunc update_func,tUInt32 my_id,string my_name,string centrals_host,tUInt32 centrals_cport,string log_file_path_and_name);

	//\brief	destructor
	virtual ~Chatter();

	/**
	 * @brief	: request a member to join the group chat
	 * @param userid	: specifying the member to request
	 * @param centrals_host	:
	 * @param centrals_port	:
	 * @return	: the outgoing task id by which to get the task status,or failed with 0
	 */
	tUInt32 InvitePeer(tUInt32 userid);

	/**
	 * @brief	: transfer file file_path_and_name to userid
	 * @param userid	:
	 * @param file_path_and_name	:
	 * @return	: the task id or failed with 0
	 */
	tUInt32 Transfer(tUInt32 userid,string file_path_and_name);

	/**
	 * @brief	: Query the status of the specific task,if tid==0, get all task status of the otconn to the remote_host.
	 * @param hconn	: the remote host the task targets at
	 * @param tid			: the task id within the tconn to the remote_host
	 * @return	: the task status or null if there is no such a status registered
	 */
	tBool	QueryTStatus(tUInt32 tid) const;

	/**
	 * @brief	: cancel the outgoing task
	 * @param tid			: the id of the task to be cancelled, if 0, cancel all related to this remote host
	 * @return	: true if succeeded, or false.
	 */
	tBool CancelT(tUInt32 tid);

	void Update4StatusChanged(void);

	/**
	 * @brief	: set the shutdown flag
	 */
	void Shutdown(void);

	string GetMyName(void) const;
	tUInt32 GetMyId(void) const;

	tChatterState ChatterState(void) const;

protected:
	//
	virtual void Execute(Thread::Arg arg);

private:
////////////////////////////////////////////////////
// private methods
////////////////////////////////////////////////////
	void SetChatterState(tChatterState chatterstate);

	GroupMgr* _groupmgr;
	TStatusMgr* _tstatusmgr;
	STConn* _stconn;

	tUpdateFunc _update_func;

	tChatterState _chatter_state;

	string	_myname;
	tUInt32	_myid;
	string	_centrals_host;	
	tUInt32 _centrals_cport;	//CentralS port for axchatter to communicate
	string	_log_file_path_and_name;

	tBool _is_shutdown_requested;
};

#endif //__CHATTER_HXX__